package com.yanqu.road.entity.admin;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

public class AdminResult {

    private int code = 200;

    private String msg = "操作成功";

    private JSONObject data = new JSONObject();

    public static AdminResult successCode(int code) {
        AdminResult result = new AdminResult();
        result.setCode(code);
        return result;
    }

    public static AdminResult failCode(int code, String msg) {
        AdminResult result = new AdminResult();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static AdminResult failMsg(String msg) {
        AdminResult result = new AdminResult();
        result.setCode(-1);
        result.setMsg(msg);
        return result;
    }

    public static AdminResult defaultInstance(){
        return new AdminResult();
    }

    public int getCode() {
        return code;
    }

    public AdminResult setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public AdminResult setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public JSONObject getData() {
        return data;
    }

    public void setData(JSONObject data) {
        this.data = data;
    }

    public String toJsonString(){
        return JSON.toJSONString(this);
    }
}
